package cn.openea.perpartner.componet.web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.openea.perpartner.componet.handler.ChainHandler;
import cn.openea.perpartner.componet.web.entity.HisShareLog;
import cn.openea.perpartner.componet.web.entity.InsShareLog;
import cn.openea.perpartner.componet.web.entity.InviteLog;
import cn.openea.perpartner.componet.web.mapper.InviteLogMapper;
import cn.openea.perpartner.componet.web.service.IHisShareLogService;
import cn.openea.perpartner.componet.web.service.InsShareLogService;
import cn.openea.perpartner.componet.web.service.InviteLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 邀请记录(InviteLog)表服务实现类
 *
 * @author Weird077
 * @since 2023-03-01 15:40:13
 */
@Service
public class InviteLogServiceImpl extends ServiceImpl<InviteLogMapper, InviteLog> implements InviteLogService, ChainHandler {
    @Resource
    private IHisShareLogService hisShareLogService;
    @Resource
    private InsShareLogService insShareLogService;

    @Override
    public boolean execute(Map<String, Object> params) {
        InviteLog inviteLog = new InviteLog();
        String shareId = (String) params.get("shareId");
        String targetUrl;
        String inviter;
        String inviterName;
        InsShareLog insShareLog = insShareLogService.getById(shareId);
        if (BeanUtil.isNotEmpty(insShareLog)) {
            targetUrl = insShareLog.getShareAddress();
            inviter = insShareLog.getInviter();
            inviterName = insShareLog.getInviterName();
        } else {
            HisShareLog hisShareLog = hisShareLogService.getById(shareId);
            targetUrl = hisShareLog.getShareAddress();
            inviter = hisShareLog.getInviter();
            inviterName = hisShareLog.getInviterName();
        }
        inviteLog.setInviter(inviter);
        inviteLog.setInviterName(inviterName);
        inviteLog.setShareId((String) params.get("shareId"));
        inviteLog.setInvitees((String) params.get("userId"));
        inviteLog.setInviteesName((String) params.get("nickName"));
        inviteLog.setStepStatus((String) params.get("stepStatus"));
        inviteLog.setUnionId((String) params.get("unionId"));
        inviteLog.setTargetUrl(targetUrl);
        return save(inviteLog);
    }
}

